<?php
namespace App\Helpers;

use Illuminate\Http\Response;
use Symfony\Component\HttpFoundation\Response as FoundationResponse;

/**
 * 接口响应
 * @package App\Helpers
 */
trait ApiResponse
{
    /**
     * 返回状态码
     * @var int
     */
    protected $resStatusCode = FoundationResponse::HTTP_OK;

    /**
     * 显示信息
     * @param string $type
     * @param string $msg
     * @param array $otherData
     * @param string $url
     * @return \Illuminate\Http\JsonResponse
     */
    public function responseJson($code = 0, $msg = '',$responseData = [])
    {
        return response()->json([
            'code'=>$code,
            'message'=> $msg,
            'data'=>$responseData
        ]);
    }

    /**
     * 成功提示
     * @param string $msg
     * @param $responseData
     */
    public function success($msg = '成功', $responseData = [])
    {
        return $this->responseJson(0, $msg, $responseData);
    }

    /**
     * 错误提示
     * @param string $msg
     * @param $responseData
     */
    public function error($msg = '错误', $responseData = [])
    {
        return $this->responseJson(-1, $msg, $responseData);
    }
}
